<?php
/*
 * This file is part of the oGUI package.
 * (c) 2010 Martin Vancura, DiS. <vancura@martinvancura.cz>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
*/

/**
 * OgHtml.
 * Static presentation of html conventions
 *
 * @package    oGUI
 * @subpackage core
 * @author     Martin Vancura, DiS. <vancura@martinvancura.cz>
 */
class OgHtml {

  /**
   * Returns start tag string with parameters
   *
   * @author  Martin Vancura, DiS. <vancura@martinvancura.cz>
   * @access  public
   * @param   String $name
   * @param   Array $attributes
   * @return  String
   */
  public static function startTag($name, $attributes) {
    $html_str = '<'.$name;
    if($attributes) {
      foreach ($attributes as $attr_name => $value) {
        $html_str .= ' '.$attr_name.'="'.$value.'"';
      }
    }
    if(self::isUnpaired($name)) $html_str .= ' /';
    $html_str .= '>';

    return $html_str;
  }

  /**
   * Returns end tag
   * 
   * @author  Martin Vancura, DiS. <vancura@martinvancura.cz>
   * @access  public
   * @param String $name
   * @return String
   */
  public static function endTag($name) {
    if(!self::isUnpaired($name)) return '</'.$name.'>';
  }

  /**
   * Returns tabs level
   *
   * @author  Martin Vancura, DiS. <vancura@martinvancura.cz>
   * @access  public
   * @param Int $num
   * @return Stkring
   */
  public static function tabs($num) {
    $tabs = '';
    for($ri = 0; $ri < $num ; $ri++) {
      $tabs .= "  ";
    }
    return $tabs;
  }

  public static function isUnpaired($tagname){
    if(in_array($tagname, self::$unpairedTags)) {
      return true;
    }
    else {
      return false;
    }
  }

  private static $unpairedTags = array(
    'link',
    'br',
    'img'
  );
}
?>
